package com.example.administrator.smartdevice.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.administrator.smartdevice.R;
import com.example.administrator.smartdevice.model.MessageModel;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by Administrator on 2018/1/22.
 */

public class AuthorizedAdapter extends BaseQuickAdapter<MessageModel, BaseViewHolder> {
    public AuthorizedAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageModel item) {
        if (item.getMessageStatus().equals("0")) {
            helper.setVisible(R.id.fragment_authorized_item_img_more, false);
        } else if (item.getMessageStatus().equals("1")) {
            helper.setGone(R.id.fragment_authorized_item_ll, false);
        }

        if (item.getApplicantName() != null && !item.getApplicantName().equals("")) {
            helper.setText(R.id.fragment_authorized_item_tv_applicant, "申请人：" + item.getApplicantName());
        } else {
            helper.setText(R.id.fragment_authorized_item_tv_applicant, "申请人：未设置");
        }

        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        helper.setText(R.id.fragment_authorized_item_tv_time, sdf.format(item.getInsertTime()));

        helper.setText(R.id.fragment_authorized_item_tv_telephone, "联系电话：" + item.getMessageApplicant());
        helper.setText(R.id.fragment_authorized_item_tv_device_title, "申请设备：" + item.getApplianceName() + "(" + item.getApplianceId() + ")");

        helper.addOnClickListener(R.id.fragment_authorized_item_bt_ignore);
        helper.addOnClickListener(R.id.fragment_authorized_item_bt_authorized);
        helper.addOnClickListener(R.id.fragment_authorized_item_img_more);
    }
}
